package com.example.hanqinshan.gifttalk.welcome;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.example.hanqinshan.gifttalk.MainActivity;
import com.example.hanqinshan.gifttalk.R;

import retrofit2.http.HEAD;

/**
 * Created by Risky57 on 2017/6/27.
 */

public class WelcomeActivity extends Activity {

    //定义的倒计时时间, n秒
    private int count = 5;
    private TextView mTextSkip;
    //倒计时的定时器
    private CountDownTimer mTimer;

    @Override
    protected void onCreate (@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);
        mTextSkip = (TextView) findViewById(R.id.text_skip);


//两个参数：1.定时器的总时长，2.定时器的间隔时间
        mTimer = new CountDownTimer(count * 1000 + 500, 1000) {
            @Override
            //每隔一次间隔时间都会执行
            public void onTick (long millisUntilFinished) {

                //每次执行的时候都会在TextView显示倒计时

                mTextSkip.setText(count-- + "秒");
            }

            //定时器结束执行
            @Override
            public void onFinish () {
                //跳转到MainActivity
                toMainActivity();
            }
        };

        //开启定时器
        mTimer.start();

    }
    //用来显示倒计时的Testview 点击事件



//用来显示倒计时TextView的点击事件
    public void onSkip (View view) {
        //取消倒计时
        mTimer.cancel();
        //跳转

        toMainActivity();
    }

    private void toMainActivity(){
        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
        finish();
    }

}
